package com.superbytecode.cloud.safety.ratelimit.limiter;

import com.superbytecode.cloud.common.utils.http.HttpRequestUtil;
import com.superbytecode.cloud.safety.ratelimit.RateLimiter;
import com.superbytecode.cloud.safety.ratelimit.model.RateLimitReq;
import lombok.extern.slf4j.Slf4j;

/**
 * All rights Reserved, Designed By www.super-master.com
 *
 * @ProjectName: beacon-cloud
 * @Package: com.superbytecode.cloud.safety.ratelimit.limiter
 * @ClassName: IPRateLimiter
 * @Description: [IP限流器]
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/11/13 15:12
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Slf4j
public class IPRateLimiter extends RateLimiter {
    /**
     * 获取key
     *
     * @param rateLimitReq 请求参数
     * @return key
     */
    @Override
    public String obtainKey(RateLimitReq rateLimitReq) {
        String remoteAddress = HttpRequestUtil.obtainRemoteAddress();
        log.info("使用IP限流,IP: {}", remoteAddress);
        return remoteAddress;
    }
}